<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!-- 搜索框 -->
      <el-col :span="5" :xs="24" :offset="10">
        <div class="head-container">
          <el-input
              v-model="queryParams.warningName"
              placeholder="多个内容，空格分隔"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
        </div>
      </el-col>
        <el-row :gutter="20" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:warning:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:warning:edit']"
            >编辑</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:warning:remove']"
            >导入</el-button>
          </el-col>
          <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:role:export']"
        >导出</el-button>
      </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="warningList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="编号" align="center" key="warningId"  prop="warningId" v-if="columns[0].visible" />
          <el-table-column label="警示牌名称" align="center" key="warningName" prop="warningName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
          <el-table-column label="警示牌类别" align="center" key="warningCategory"  prop="warningCategory" v-if="columns[2].visible" :show-overflow-tooltip="true"
          :formatter="cz"/>
          <el-table-column label="安装日期" align="center"  key="installDate" prop="installDate" v-if="columns[3].visible" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
          <span>{{ parseTime(scope.row.installDate) }}</span>
        </template>
            </el-table-column>
          <el-table-column label="配备地点" align="center" key="location" prop="location" v-if="columns[4].visible" width="120" />
          <el-table-column label="编辑时间" align="center" key="editTime" prop="editTime" v-if="columns[5].visible" width="160"> </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.userId !== 1">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:warning:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:warning:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-row>
    <el-row>
        <el-col :span="2">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:warning:remove']"
              style="margin: 20px;"
            >批量删除</el-button>
          </el-col>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
          style="float:right;"
        />
    </el-row>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form"  inline>
        <el-row>
          
            <el-form-item label="警示牌名称" prop="warningName" >
              <el-input v-model="form.warningName" placeholder="请输入警示牌名称"  maxlength="40" />
          </el-form-item>
         
          <!-- <el-select v-model="form.riskLevel" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.value"
              :value="item.value">
            </el-option>
          </el-select> -->
          <el-form-item label="警示牌类别">
            <el-select v-model="form.warningCategory" placeholder="未选择">
              <el-option label="禁止" value="1"></el-option>
              <el-option label="警告" value="2"></el-option>
              <el-option label="指令" value="3"></el-option>
              <el-option label="提示" value="4"></el-option>
              <el-option label="文字辅助" value="5"></el-option>
              <el-option label="综合性" value="6"></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
        <el-form-item label="安装日期">
            <el-col :span="11">
              <el-date-picker type="date" placeholder="选择日期" v-model="form.installDate" ></el-date-picker>
            </el-col>
        </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="配备地点" prop="email">
              <el-input v-model="form.location" placeholder="" maxlength="50" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
 
import { listWarning , getWarning, delWarning, addWarning, updateWarning} from "@/api/system/warning";

  
export default {
  name: "Warning",
  dicts: ['sys_normal_disable', 'sys_warning_sex'],
  components: { },
  data() {
    return {
      warningList:null,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
    //   options:[{
    //     value:'未指定'
    //   },{
    //     value:'禁止'
    //   },{
    //     value:'警告'
    //   },{
    //     value:'指令'
    //   },{
    //     value:'提示'
    //   },{
    //     value:'文字辅助'
    //   },{
    //     value:'综合性'
    //   },
    // ],
      // 弹出层标题
      title: "",
      // 日期范围
      dateRange: [],
      // 是否显示弹出层
      open: false,
      // 岗位选项
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        
      },
      // 列信息
      columns: [
        { key: 0, label: `警示牌编号`, visible: true },
        { key: 1, label: `警示牌名称名称`, visible: true },
        { key: 2, label: `警示牌类别`, visible: true },
        { key: 3, label: `安装日期`, visible: true },
        { key: 4, label: `配备地点`, visible: true },
        { key: 5, label: `编辑时间`, visible: true }
      ],
      
    }
  },
  created(){
          this.getList();
      },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listWarning(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        console.info(response+ "...............")
          this.warningList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    cz:function(row, column, cellValue, index){
        console.info(row)
        if(row.warningCategory==0){
          return "未指定"
        }else if(row.warningCategory==1){
          return "禁止"
        }else if(row.warningCategory==2){
          return "警告"
        }else if(row.warningCategory==3){
          return "指令"
        }else if(row.warningCategory==4){
          return "提示"
        }else if(row.warningCategory==5){
          return "文字辅助"
        }else if(row.warningCategory==6){
          return "综合性"
        }
      },
   
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {
        
      }},
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.warningId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // getWarning().then(response => {
      //   this.open = true;
      //   this.title = "添加用户";
      // });
      this.open = true;
      this.title = "警示牌管理详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const warningId = row.warningId || this.ids;
      getWarning(warningId).then(response => {
        this.form = response;
        this.open = true;
        this.title = "修改警示牌"; 
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.warningId != undefined) {
            updateWarning(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWarning(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const warningIds = row.warningId || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + warningIds + '"的数据项？').then(function() {
        return delWarning(warningIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('aqsc/warning/export', {
        ...this.queryParams
      }, `warning_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>